﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.admin.templates.lable
{
    public partial class freedomlabel_list : System.Web.UI.Page
    {
        YXShop.BLL.Templates.FreeLabel freeBll = new YXShop.BLL.Templates.FreeLabel();
        protected void Page_Load(object sender, EventArgs e)
        {
            YXShop.Common.PromptInfo.Popedom("011003001");
            if(!IsPostBack){
                #region Ajax
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    YXShop.Common.PromptInfo.Popedom("011003003","对不起，您没有权限进行删除");
                    string types = Request["Option"].Trim();
                    string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        freeBll.Delete(Convert.ToInt32(id));
                    }
                    if (types == "delAll")
                    {
                        freeBll.DeleteAll(id);
                    }
                    Response.End();
                    return;
                }
                #endregion Ajax
                this.litFree.Text = GetTableList();
            }
        }

        #region 获取Table

        public string GetTableList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = freeBll.GetListAll();
            table.AddHeadCol("","选择");
            table.AddHeadCol("","标签名称");
            table.AddHeadCol("","建立日期");
            table.AddHeadCol("","标签类型");
            table.AddHeadCol("","描述");
            table.AddHeadCol("","操作");
            table.AddRow();
            if(dataPage.DataReader!=null){
                while(dataPage.DataReader.Read()){
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=" + dataPage.DataReader["free_id"] + " />");
                    table.AddCol(dataPage.DataReader["free_name"].ToString());
                    table.AddCol(dataPage.DataReader["free_createtime"].ToString());
                    table.AddCol(ShowType(dataPage.DataReader["free_labeltype"].ToString()));
                    table.AddCol(dataPage.DataReader["free_description"].ToString());
                    table.AddCol("<a href='freedomlabel_edit.aspx?id=" + dataPage.DataReader["free_id"].ToString() + "'>修改</a>&nbsp;<a href='javascript:Del(" + dataPage.DataReader["free_id"] + ")'>彻底删除</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }

        #endregion

        #region 类别
        /// <summary>
        /// 类别
        /// </summary>
        public string ShowType(string id)
        {
            string str = "";
            YXShop.BLL.Templates.LabelType typeBll = new YXShop.BLL.Templates.LabelType();
            YXShop.Model.Templates.LabelType model = typeBll.GetModel(Convert.ToInt32(id));
            if(model!=null){
                str = model.Name.ToString();
            }
            return str;
        }
        #endregion

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            this.litFree.Text = GetTableList();
        }
    }
}
